package com.fr.cell;

import com.fr.base.ColumnRow;
import com.fr.base.background.Background;
import com.fr.base.background.ColorBackground;
import com.fr.base.background.ImageBackground;
import com.fr.base.core.GraphHelper;
import com.fr.base.core.antlr.ANTLRException;
import com.fr.cell.core.GridUtils;
import com.fr.report.CellElement;
import com.fr.report.FloatElement;
import com.fr.report.Margin;
import com.fr.report.PaperSize;
import com.fr.report.Report;
import com.fr.report.ReportSettings;
import com.fr.report.TemplateReport;
import com.fr.report.cellElement.CellExpandAttr;
import com.fr.report.cellElement.CellGUIAttr;
import com.fr.report.cellElement.CellPageAttr;
import com.fr.report.cellElement.Formula;
import com.fr.report.core.DynamicValueList;
import com.fr.report.core.PaintUtils;
import com.fr.report.core.ReportHelper;
import com.fr.report.core.ReportUtils;
import com.fr.report.script.Calculator;
import com.fr.util.Utils;
import java.awt.AlphaComposite;
import java.awt.Color;
import java.awt.Composite;
import java.awt.Dimension;
import java.awt.Graphics;
import java.awt.Graphics2D;
import java.awt.Rectangle;
import java.awt.Shape;
import java.awt.geom.Area;
import java.awt.geom.Dimension2D;
import java.awt.geom.GeneralPath;
import java.awt.geom.Line2D;
import java.awt.geom.Line2D.Double;
import java.awt.geom.Rectangle2D;
import java.awt.geom.Rectangle2D.Double;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
import javax.swing.JComponent;
import javax.swing.UIManager;
import javax.swing.plaf.ComponentUI;

public class GridUI extends ComponentUI
{
  public static int INVALID_INTEGER = -2147483648;
  private transient Dimension gridSize;
  private transient int verticalValue;
  private transient int horizontalValue;
  private transient double paperPaintWidth;
  private transient double paperPaintHeight;
  private transient DynamicValueList rowHeightList;
  private transient DynamicValueList columnWidthList;
  private transient int verticalEndValue;
  private transient int horizontalEndValue;
  private List paintCellElementList = new ArrayList();
  private List paintCellElementRectangleList = new ArrayList();
  private List paginateLineList = new ArrayList();
  private static Background WHITE_Backgorund = ColorBackground.getInstance(Color.WHITE);
  private static Background LIGHT_Backgorund = ColorBackground.getInstance(new Color(250, 250, 250));
  private CellElementPainter painter = new CellElementPainter();
  private Rectangle2D.Double left_col_row_rect = new Rectangle2D.Double(0.0D, 0.0D, 0.0D, 0.0D);
  private Rectangle2D.Double top_col_row_rect = new Rectangle2D.Double(0.0D, 0.0D, 0.0D, 0.0D);
  private Rectangle2D.Double back_or_selection_rect = new Rectangle2D.Double(0.0D, 0.0D, 0.0D, 0.0D);
  private Rectangle2D.Double drag_cell_rect = new Rectangle2D.Double(0.0D, 0.0D, 0.0D, 0.0D);
  private Rectangle2D.Double cell_back_rect = new Rectangle2D.Double(0.0D, 0.0D, 0.0D, 0.0D);
  private Rectangle2D.Double tmpRectangle = new Rectangle2D.Double(INVALID_INTEGER, INVALID_INTEGER, INVALID_INTEGER, INVALID_INTEGER);

  private void paintBackground(Graphics paramGraphics, Grid paramGrid, Report paramReport, ReportSettings paramReportSettings)
  {
    Object localObject2;
    Graphics2D localGraphics2D = (Graphics2D)paramGraphics;
    this.back_or_selection_rect.setRect(0.0D, 0.0D, this.gridSize.getWidth(), this.gridSize.getHeight());
    if (paramGrid.isEnabled())
      localGraphics2D.setPaint(Color.WHITE);
    else
      localGraphics2D.setPaint(UIManager.getColor("control"));
    GraphHelper.fill(localGraphics2D, this.back_or_selection_rect);
    this.paperPaintWidth = 0.0D;
    this.paperPaintHeight = 0.0D;
    if (paramGrid.isShowPaginateLine())
    {
      localObject1 = paramReportSettings.getPaperSize();
      localObject2 = paramReportSettings.getMargin();
      double d1 = ((PaperSize)localObject1).getWidth();
      double d3 = ((PaperSize)localObject1).getHeight();
      if (paramReportSettings.getOrientation() == 1)
      {
        d1 = ((PaperSize)localObject1).getHeight();
        d3 = ((PaperSize)localObject1).getWidth();
      }
      this.paperPaintWidth = ((d1 - ((Margin)localObject2).getLeft() - ((Margin)localObject2).getRight()) * paramReportSettings.getResolution());
      this.paperPaintHeight = ((d3 - ((Margin)localObject2).getTop() - ((Margin)localObject2).getBottom() - paramReportSettings.getHeaderHeight() - paramReportSettings.getFooterHeight()) * paramReportSettings.getResolution());
    }
    Object localObject1 = paramReportSettings.getBackground();
    if (localObject1 != null)
    {
      if ((paramGrid.isEnabled()) && (!(localObject1 instanceof ImageBackground)))
        ((Background)localObject1).paint(localGraphics2D, this.back_or_selection_rect);
      if ((paramGrid.isEditable()) && (localObject1 instanceof ImageBackground))
      {
        if (!(paramGrid.isShowPaginateLine()))
        {
          localObject2 = paramReportSettings.getPaperSize();
          Margin localMargin = paramReportSettings.getMargin();
          double d2 = ((PaperSize)localObject2).getWidth();
          double d4 = ((PaperSize)localObject2).getHeight();
          if ((paramReportSettings.getOrientation() == 1) && (((PaperSize)localObject2).getWidth() < ((PaperSize)localObject2).getHeight()))
          {
            d2 = Math.max(((PaperSize)localObject2).getWidth(), ((PaperSize)localObject2).getHeight());
            d4 = Math.min(((PaperSize)localObject2).getWidth(), ((PaperSize)localObject2).getHeight());
          }
          else if ((paramReportSettings.getOrientation() == 0) && (((PaperSize)localObject2).getWidth() > ((PaperSize)localObject2).getHeight()))
          {
            d2 = Math.min(((PaperSize)localObject2).getWidth(), ((PaperSize)localObject2).getHeight());
            d4 = Math.max(((PaperSize)localObject2).getWidth(), ((PaperSize)localObject2).getHeight());
          }
          this.paperPaintWidth = ((d2 - localMargin.getLeft() - localMargin.getRight()) * paramReportSettings.getResolution());
          this.paperPaintHeight = ((d4 - localMargin.getTop() - localMargin.getBottom() - paramReportSettings.getHeaderHeight() - paramReportSettings.getFooterHeight()) * paramReportSettings.getResolution());
        }
        localObject2 = (ImageBackground)localObject1;
        int i = this.columnWidthList.getRangeValue(0, this.horizontalValue);
        int j = this.rowHeightList.getRangeValue(0, this.verticalValue);
        for (int k = 0; k * this.paperPaintWidth < this.gridSize.getWidth(); ++k)
          for (int l = 0; l * this.paperPaintHeight < this.gridSize.getHeight(); ++l)
          {
            this.back_or_selection_rect.setRect(k * this.paperPaintWidth, l * this.paperPaintHeight, this.paperPaintWidth, this.paperPaintHeight);
            ((ImageBackground)localObject2).paint2(localGraphics2D, this.back_or_selection_rect, i, j);
          }
        this.back_or_selection_rect.setRect(0.0D, 0.0D, this.gridSize.getWidth(), this.gridSize.getHeight());
      }
    }
  }

  private void paintGridLine(Graphics paramGraphics, Grid paramGrid, double paramDouble1, double paramDouble2)
  {
    double d1;
    double d4;
    Graphics2D localGraphics2D = (Graphics2D)paramGraphics;
    int i = this.horizontalEndValue;
    int j = this.verticalEndValue;
    int k = paramGrid.getHorizontalBeginValue();
    int l = paramGrid.getVerticalBeginValue();
    Line2D.Double localDouble = new Line2D.Double(0.0D, 0.0D, 0.0D, 0.0D);
    localGraphics2D.setPaint(paramGrid.getGridLineColor());
    GraphHelper.setStroke(localGraphics2D, GraphHelper.getStroke(1));
    this.paginateLineList.clear();
    double d2 = 0.0D;
    double d3 = 0.0D;
    for (int i1 = 0; i1 <= i; ++i1)
    {
      int i2;
      if (i1 == 0)
      {
        i1 = k;
        for (i2 = 0; i2 < k; ++i2)
        {
          d1 = this.columnWidthList.get(i2);
          d3 += d1;
          if (d3 >= this.paperPaintWidth)
            d3 = d1;
        }
      }
      d1 = this.columnWidthList.get(i1);
      d3 += d1;
      if ((paramGrid.isShowPaginateLine()) && (d3 >= this.paperPaintWidth))
      {
        this.paginateLineList.add(new Line2D.Double(d2, 0.0D, d2, this.gridSize.height));
        d3 = d1;
      }
      d2 += d1;
    }
    d2 = 0.0D;
    for (i1 = 0; i1 < this.horizontalEndValue; ++i1)
    {
      if (i1 == 0)
        i1 = k;
      d1 = this.columnWidthList.get(i1);
      if (paramGrid.isShowGridLine())
      {
        localDouble.setLine(d2, 0.0D, d2, paramDouble2);
        localGraphics2D.draw(localDouble);
      }
      d2 += d1;
    }
    if (paramGrid.isShowGridLine())
    {
      localGraphics2D.setPaint(paramGrid.getGridLineColor());
      GraphHelper.drawLine(localGraphics2D, d2, 0.0D, d2, paramDouble2);
    }
    double d5 = 0.0D;
    double d6 = 0.0D;
    for (int i3 = 0; i3 <= j; ++i3)
    {
      int i4;
      if (i3 == 0)
      {
        i3 = l;
        for (i4 = 0; i4 < l; ++i4)
        {
          d4 = this.rowHeightList.get(i4);
          d6 += d4;
          if (d6 >= this.paperPaintHeight)
            d6 = d4;
        }
      }
      d4 = this.rowHeightList.get(i3);
      d6 += d4;
      if ((paramGrid.isShowPaginateLine()) && (d6 >= this.paperPaintHeight))
      {
        this.paginateLineList.add(new Line2D.Double(0.0D, d5, this.gridSize.width, d5));
        d6 = d4;
      }
      d5 += d4;
    }
    d5 = 0.0D;
    for (i3 = 0; i3 < this.verticalEndValue; ++i3)
    {
      if (i3 == 0)
        i3 = l;
      d4 = this.rowHeightList.get(i3);
      if (paramGrid.isShowGridLine())
      {
        localDouble.setLine(0.0D, d5, paramDouble1, d5);
        localGraphics2D.draw(localDouble);
      }
      d5 += d4;
    }
    if (paramGrid.isShowGridLine())
    {
      localGraphics2D.setPaint(paramGrid.getGridLineColor());
      GraphHelper.drawLine(localGraphics2D, 0.0D, d5, paramDouble1, d5);
    }
  }

  private void paintCellElements(Graphics paramGraphics, Grid paramGrid, Report paramReport)
  {
    Object localObject;
    double d3;
    double d4;
    GeneralPath localGeneralPath;
    Graphics2D localGraphics2D = (Graphics2D)paramGraphics;
    CellElement localCellElement1 = null;
    ReportPane localReportPane = paramGrid.getReportPane();
    GridSelection localGridSelection = localReportPane.getGridSelection();
    int i = localGridSelection.getType();
    if (i == 0)
    {
      Rectangle localRectangle = localGridSelection.getEditRectangle();
      localCellElement1 = paramReport.getCellElement(localRectangle.x, localRectangle.y);
    }
    int j = paramGrid.getHorizontalBeginValue();
    int k = paramGrid.getVerticalBeginValue();
    Shape localShape = null;
    CellElement localCellElement2 = null;
    Iterator localIterator = paramReport.intersect(j, k, this.horizontalEndValue - j, this.verticalEndValue - k);
    double d1 = this.columnWidthList.getRangeValue(0, this.horizontalValue);
    double d2 = this.rowHeightList.getRangeValue(0, this.verticalValue);
    this.left_col_row_rect.setRect(0.0D, 0.0D, 0.0D, 0.0D);
    this.top_col_row_rect.setRect(0.0D, 0.0D, 0.0D, 0.0D);
    while (true)
    {
      while (true)
      {
        if (!(localIterator.hasNext()))
          break label561;
        localCellElement2 = (CellElement)localIterator.next();
        if (localCellElement2 != null)
          break;
      }
      calculateForcedPagingOfCellElement(localReportPane, localCellElement2, d1, d2);
      localObject = localCellElement2.getCellGUIAttr();
      if (localObject == null)
        localObject = CellGUIAttr.DEFAULT_CELLGUIATTR;
      if (localCellElement1 == localCellElement2)
      {
        CellExpandAttr localCellExpandAttr = localCellElement2.getCellExpandAttr();
        if (localCellExpandAttr != null)
        {
          ColumnRow localColumnRow1 = localCellExpandAttr.getLeftParentColumnRow();
          if (ColumnRow.validate(localColumnRow1))
            caculateScrollVisibleBounds(this.left_col_row_rect, localColumnRow1.getColumn(), localColumnRow1.getRow(), 1, 1);
          ColumnRow localColumnRow2 = localCellExpandAttr.getUpParentColumnRow();
          if (ColumnRow.validate(localColumnRow2))
            caculateScrollVisibleBounds(this.top_col_row_rect, localColumnRow2.getColumn(), localColumnRow2.getRow(), 1, 1);
        }
      }
      caculateScrollVisibleBounds(this.tmpRectangle, localCellElement2.getColumn(), localCellElement2.getRow(), localCellElement2.getColumnSpan(), localCellElement2.getRowSpan());
      localShape = localGraphics2D.getClip();
      localGraphics2D.clip(this.tmpRectangle);
      localGraphics2D.translate(this.tmpRectangle.getX() + 1.0D, this.tmpRectangle.getY() + 1.0D);
      this.cell_back_rect.setRect(0.0D, 0.0D, this.tmpRectangle.getWidth() - 1.0D, this.tmpRectangle.getHeight() - 1.0D);
      if ((localCellElement2.getColumnSpan() > 1) || (localCellElement2.getRowSpan() > 1))
        WHITE_Backgorund.paint(localGraphics2D, this.cell_back_rect);
      this.paintCellElementList.add(localCellElement2);
      this.paintCellElementRectangleList.add(this.tmpRectangle.clone());
      l = (int)this.tmpRectangle.getWidth();
      int i1 = (int)this.tmpRectangle.getHeight();
      this.painter.paintBackground(localGraphics2D, paramReport, localCellElement2, l, i1);
      this.painter.paintContent(localGraphics2D, paramReport, localCellElement2, l, i1);
      localGraphics2D.translate(-this.tmpRectangle.getX() - 1.0D, -this.tmpRectangle.getY() - 1.0D);
      localGraphics2D.setClip(localShape);
    }
    for (int l = 0; l < this.paintCellElementList.size(); ++l)
    {
      label561: localCellElement2 = (CellElement)this.paintCellElementList.get(l);
      localObject = (Rectangle2D.Double)this.paintCellElementRectangleList.get(l);
      CellGUIAttr localCellGUIAttr = localCellElement2.getCellGUIAttr();
      if (localCellGUIAttr == null)
        localCellGUIAttr = CellGUIAttr.DEFAULT_CELLGUIATTR;
      localGraphics2D.translate(((Rectangle2D.Double)localObject).getX(), ((Rectangle2D.Double)localObject).getY());
      this.painter.paintBorder(localGraphics2D, paramReport, localCellElement2, (int)((Rectangle2D.Double)localObject).getWidth(), (int)((Rectangle2D.Double)localObject).getHeight());
      localGraphics2D.translate(-((Rectangle2D.Double)localObject).getX(), -((Rectangle2D.Double)localObject).getY());
    }
    if ((validate(this.left_col_row_rect)) && (this.left_col_row_rect.getHeight() > 5.0D))
    {
      localGraphics2D.setPaint(Color.BLUE);
      d3 = this.left_col_row_rect.getX() + 4.0D;
      d4 = this.left_col_row_rect.getY() + this.left_col_row_rect.getHeight() / 2.0D;
      GraphHelper.drawLine(localGraphics2D, d3, d4 - 5.0D, d3, d4 + 5.0D);
      localGeneralPath = new GeneralPath(0, 3);
      localGeneralPath.moveTo((float)d3, (float)d4 + 5.0F);
      localGeneralPath.lineTo((float)d3 + 3.0F, (float)d4 + 5.0F - 4.0F);
      localGeneralPath.lineTo((float)d3 - 2.0F, (float)d4 + 5.0F - 4.0F);
      GraphHelper.fill(localGraphics2D, localGeneralPath);
    }
    if ((validate(this.top_col_row_rect)) && (this.top_col_row_rect.getWidth() > 5.0D))
    {
      localGraphics2D.setPaint(Color.BLUE);
      d3 = this.top_col_row_rect.getX() + this.top_col_row_rect.getWidth() / 2.0D;
      d4 = this.top_col_row_rect.getY() + 4.0D;
      GraphHelper.drawLine(localGraphics2D, d3 - 5.0D, d4, d3 + 5.0D, d4);
      localGeneralPath = new GeneralPath(0, 3);
      localGeneralPath.moveTo((float)d3 + 5.0F, (float)d4);
      localGeneralPath.lineTo((float)d3 + 5.0F - 4.0F, (float)d4 + 3.0F);
      localGeneralPath.lineTo((float)d3 + 5.0F - 4.0F, (float)d4 - 3.0F);
      GraphHelper.fill(localGraphics2D, localGeneralPath);
    }
  }

  private void paintPaginateLines(Graphics paramGraphics, Grid paramGrid)
  {
    Graphics2D localGraphics2D = (Graphics2D)paramGraphics;
    if (this.paginateLineList.size() > 0)
    {
      Object localObject = new Line2D.Double(0.0D, 0.0D, 0.0D, 0.0D);
      for (int i = 0; i < this.paginateLineList.size(); ++i)
      {
        localObject = (Line2D)this.paginateLineList.get(i);
        for (j = i + 1; j < this.paginateLineList.size(); ++j)
        {
          Line2D localLine2D = (Line2D)this.paginateLineList.get(j);
          if ((localLine2D.getX1() == ((Line2D)localObject).getX1()) && (localLine2D.getX2() == ((Line2D)localObject).getX2()) && (localLine2D.getY1() == ((Line2D)localObject).getY1()) && (localLine2D.getY2() == ((Line2D)localObject).getY2()))
            this.paginateLineList.remove(j);
        }
      }
      localGraphics2D.setPaint(paramGrid.getPaginationLineColor());
      localGraphics2D.setXORMode(Utils.getXORColor(paramGrid.getPaginationLineColor()));
      GraphHelper.setStroke(localGraphics2D, GraphHelper.getStroke(9));
      i = 0;
      int j = this.paginateLineList.size();
      while (i < j)
      {
        localGraphics2D.draw((Shape)this.paginateLineList.get(i));
        ++i;
      }
      localGraphics2D.setPaintMode();
    }
  }

  private void paintGridSelection(Graphics paramGraphics, Grid paramGrid, Report paramReport)
  {
    ColumnRow[] arrayOfColumnRow;
    Area localArea3;
    int l;
    Graphics2D localGraphics2D = (Graphics2D)paramGraphics;
    GridSelection localGridSelection = paramGrid.getReportPane().getGridSelection();
    int i = localGridSelection.getType();
    if ((i == 0) && (paramGrid.isCellSelectable()))
    {
      Object localObject1;
      Object localObject2;
      Rectangle localRectangle1 = localGridSelection.getEditRectangle();
      int j = localGridSelection.getCellRectangleCount();
      Area localArea1 = new Area();
      Area localArea2 = new Area();
      caculateScrollVisibleBounds(this.tmpRectangle, localRectangle1);
      if (validate(this.tmpRectangle))
        localArea2.add(new Area(this.tmpRectangle));
      if (j == 1)
      {
        Rectangle localRectangle2 = localGridSelection.getFirstCellRectangle();
        caculateScrollVisibleBounds(this.tmpRectangle, localRectangle2);
        if (validate(this.tmpRectangle))
        {
          double d1 = this.tmpRectangle.getX();
          double d2 = this.tmpRectangle.getY();
          double d3 = this.tmpRectangle.getWidth();
          double d4 = this.tmpRectangle.getHeight();
          localArea1 = new Area(this.tmpRectangle);
          localArea1.add(localArea2);
          localArea1.exclusiveOr(localArea2);
          if ((localRectangle2.x != localRectangle1.x) || (localRectangle2.y != localRectangle1.y) || (localRectangle2.width != localRectangle1.width) || (localRectangle2.height != localRectangle1.height))
          {
            localObject3 = localGraphics2D.getComposite();
            localGraphics2D.setComposite(AlphaComposite.getInstance(3, 0.5F));
            localGraphics2D.setPaint(paramGrid.getSelectedBackground());
            GraphHelper.fill(localGraphics2D, localArea1);
            localGraphics2D.setComposite((Composite)localObject3);
          }
          this.back_or_selection_rect.setRect(d1 - 1.0D, d2 - 1.0D, d3 + 3.0D, d4 + 3.0D);
          Object localObject3 = new Area(this.back_or_selection_rect);
          this.back_or_selection_rect.setRect(d1 + 2.0D, d2 + 2.0D, d3 - 3.0D, d4 - 3.0D);
          ((Area)localObject3).exclusiveOr(new Area(this.back_or_selection_rect));
          this.back_or_selection_rect.setRect(d1 + d3 - 1.0D, d2 + d4 - 3.0D, 3.0D, 1.0D);
          ((Area)localObject3).exclusiveOr(new Area(this.back_or_selection_rect));
          this.back_or_selection_rect.setRect(d1 + d3 - 3.0D, d2 + d4 - 1.0D, 1.0D, 3.0D);
          ((Area)localObject3).exclusiveOr(new Area(this.back_or_selection_rect));
          this.back_or_selection_rect.setRect(d1 + d3 - 2.0D, d2 + d4 - 2.0D, 5.0D, 5.0D);
          ((Area)localObject3).add(new Area(this.back_or_selection_rect));
          localGraphics2D.setXORMode(Utils.getXORColor(paramGrid.getSelectedBorderLineColor()));
          localGraphics2D.setPaint(paramGrid.getSelectedBorderLineColor());
          GraphHelper.fill(localGraphics2D, (Shape)localObject3);
          localGraphics2D.setPaintMode();
        }
      }
      else
      {
        localArea1 = new Area();
        for (int k = 0; k < j; ++k)
        {
          localObject2 = localGridSelection.getCellRectangle(k);
          caculateScrollVisibleBounds(this.tmpRectangle, (Rectangle)localObject2);
          if (validate(this.tmpRectangle))
            localArea1.add(new Area(this.tmpRectangle));
        }
        localArea1.add(localArea2);
        localArea1.exclusiveOr(localArea2);
        localObject1 = localGraphics2D.getComposite();
        localGraphics2D.setComposite(AlphaComposite.getInstance(3, 0.5F));
        localGraphics2D.setPaint(paramGrid.getSelectedBackground());
        GraphHelper.fill(localGraphics2D, localArea1);
        localGraphics2D.setComposite((Composite)localObject1);
        localGraphics2D.setPaint(Color.blue);
        if (localArea2 != null)
          GraphHelper.draw(localGraphics2D, localArea2);
      }
      if (paramReport.getCellValue(localRectangle1.x, localRectangle1.y) instanceof Formula)
      {
        localObject1 = (Formula)paramReport.getCellValue(localRectangle1.x, localRectangle1.y);
        localObject2 = ((Formula)localObject1).getContent();
        arrayOfColumnRow = new ColumnRow[0];
        try
        {
          arrayOfColumnRow = Calculator.relatedColumnRowArray(((String)localObject2).substring(1));
        }
        catch (ANTLRException localANTLRException)
        {
        }
        localArea3 = null;
        for (l = 0; l < arrayOfColumnRow.length; ++l)
        {
          ColumnRow localColumnRow = arrayOfColumnRow[l];
          int i1 = 1;
          int i2 = 1;
          CellElement localCellElement = paramReport.getCellElement(localColumnRow.getColumn(), localColumnRow.getRow());
          if (localCellElement != null)
          {
            i1 = localCellElement.getColumnSpan();
            i2 = localCellElement.getRowSpan();
            if ((i1 > 1) || (i2 > 1))
              localColumnRow = ColumnRow.valueOf(localCellElement.getColumn(), localCellElement.getRow());
          }
          caculateScrollVisibleBounds(this.tmpRectangle, localColumnRow.getColumn(), localColumnRow.getRow(), i1, i2);
          if (validate(this.tmpRectangle))
          {
            localArea3 = new Area(new Rectangle2D.Double(this.tmpRectangle.getX(), this.tmpRectangle.getY(), this.tmpRectangle.getWidth(), this.tmpRectangle.getHeight()));
            localArea3.exclusiveOr(new Area(new Rectangle2D.Double(this.tmpRectangle.getX() + 1.0D, this.tmpRectangle.getY() + 1.0D, this.tmpRectangle.getWidth() - 2.0D, this.tmpRectangle.getHeight() - 2.0D)));
            localArea3.add(new Area(new Rectangle2D.Double(this.tmpRectangle.getX(), this.tmpRectangle.getY(), 3.0D, 3.0D)));
            localArea3.add(new Area(new Rectangle2D.Double(this.tmpRectangle.getX() + this.tmpRectangle.getWidth() - 3.0D, this.tmpRectangle.getY(), 3.0D, 3.0D)));
            localArea3.add(new Area(new Rectangle2D.Double(this.tmpRectangle.getX(), this.tmpRectangle.getY() + this.tmpRectangle.getHeight() - 3.0D, 3.0D, 3.0D)));
            localArea3.add(new Area(new Rectangle2D.Double(this.tmpRectangle.getX() + this.tmpRectangle.getWidth() - 3.0D, this.tmpRectangle.getY() + this.tmpRectangle.getHeight() - 3.0D, 3.0D, 3.0D)));
            localGraphics2D.setPaint(new Color((l + 2) * 50 % 256, (l + 1) * 50 % 256, l * 50 % 256));
            if (localArea3 != null)
              GraphHelper.fill(localGraphics2D, localArea3);
          }
        }
      }
    }
  }

  private void paintFloatElements(Graphics paramGraphics, Grid paramGrid, Report paramReport)
  {
    FloatElement localFloatElement;
    int j;
    int k;
    int l;
    int i1;
    Graphics2D localGraphics2D = (Graphics2D)paramGraphics;
    GridSelection localGridSelection = paramGrid.getReportPane().getGridSelection();
    int i = localGridSelection.getType();
    Iterator localIterator = paramReport.floatIterator();
    while (true)
    {
      do
      {
        if (!(localIterator.hasNext()))
          break label228;
        localFloatElement = (FloatElement)localIterator.next();
        j = localFloatElement.getRow();
        k = localFloatElement.getColumn();
        l = this.rowHeightList.getValueIndex((int)(this.rowHeightList.getRangeValueFromZero(j) + localFloatElement.getTopDistance() + localFloatElement.getSize().getHeight()));
      }
      while ((j < this.verticalValue) && (j > this.verticalEndValue) && (l < this.verticalValue) && (l > this.verticalValue));
      i1 = this.columnWidthList.getRangeValue(this.horizontalValue, k) + localFloatElement.getLeftDistance();
      int i2 = this.rowHeightList.getRangeValue(this.verticalValue, j) + localFloatElement.getTopDistance();
      Dimension localDimension = localFloatElement.getSize();
      localGraphics2D.translate(i1, i2);
      PaintUtils.paintFloatElement(localGraphics2D, localFloatElement, (int)localDimension.getWidth(), (int)localDimension.getHeight());
      localGraphics2D.translate(-i1, -i2);
    }
    if (i == 1)
    {
      label228: localIterator = paramReport.floatIterator();
      while (true)
      {
        if (!(localIterator.hasNext()))
          return;
        localFloatElement = (FloatElement)localIterator.next();
        if (localGridSelection.containFloatName(localFloatElement.getName()))
          break;
      }
      j = this.columnWidthList.getRangeValue(this.horizontalValue, localFloatElement.getColumn()) + localFloatElement.getLeftDistance();
      k = this.rowHeightList.getRangeValue(this.verticalValue, localFloatElement.getRow()) + localFloatElement.getTopDistance();
      l = (int)(j + localFloatElement.getSize().getWidth());
      i1 = (int)(k + localFloatElement.getSize().getHeight());
      GraphHelper.setStroke(localGraphics2D, GraphHelper.getStroke(1));
      Rectangle2D[] arrayOfRectangle2D = { new Rectangle2D.Double(j - 3, k - 3, 6.0D, 6.0D), new Rectangle2D.Double((j + l) / 2 - 3, k - 3, 6.0D, 6.0D), new Rectangle2D.Double(l - 3, k - 3, 6.0D, 6.0D), new Rectangle2D.Double(l - 3, (k + i1) / 2 - 3, 6.0D, 6.0D), new Rectangle2D.Double(l - 3, i1 - 3, 6.0D, 6.0D), new Rectangle2D.Double((j + l) / 2 - 3, i1 - 3, 6.0D, 6.0D), new Rectangle2D.Double(j - 3, i1 - 3, 6.0D, 6.0D), new Rectangle2D.Double(j - 3, (k + i1) / 2 - 3, 6.0D, 6.0D) };
      int i3 = 0;
      while (true)
      {
        if (i3 >= arrayOfRectangle2D.length);
        localGraphics2D.setPaint(Utils.getXORColor(paramGrid.getSelectedBorderLineColor()));
        GraphHelper.fill(localGraphics2D, arrayOfRectangle2D[i3]);
        localGraphics2D.setPaint(paramGrid.getSelectedBorderLineColor());
        GraphHelper.draw(localGraphics2D, arrayOfRectangle2D[i3]);
        ++i3;
      }
    }
  }

  private void paintDragCellBorder(Graphics paramGraphics, Grid paramGrid)
  {
    Graphics2D localGraphics2D = (Graphics2D)paramGraphics;
    if ((((paramGrid.getDragType() == GridUtils.DRAG_CELLSELECTION) || (paramGrid.getDragType() == GridUtils.Drag_CellSelection_BottomRight_Corner))) && (paramGrid.getDragRectangle() != null))
    {
      caculateScrollVisibleBounds(this.drag_cell_rect, paramGrid.getDragRectangle());
      localGraphics2D.setPaint(Color.GRAY);
      GraphHelper.draw(localGraphics2D, this.drag_cell_rect, 5);
    }
  }

  public void paint(Graphics paramGraphics, JComponent paramJComponent)
  {
    int i1;
    if (!(paramJComponent instanceof Grid))
      throw new IllegalArgumentException("The component c to paint must be a Grid!");
    Graphics2D localGraphics2D = (Graphics2D)paramGraphics;
    Grid localGrid = (Grid)paramJComponent;
    ReportPane localReportPane = localGrid.getReportPane();
    TemplateReport localTemplateReport = localReportPane.getEditingReport();
    ReportSettings localReportSettings = ReportUtils.getReportSettings(localTemplateReport);
    this.rowHeightList = ReportHelper.getRowHeightList(localTemplateReport);
    this.columnWidthList = ReportHelper.getColumnWidthList(localTemplateReport);
    this.verticalValue = localGrid.getVerticalValue();
    int i = localGrid.getVerticalExtent();
    this.horizontalValue = localGrid.getHorizontalValue();
    int j = localGrid.getHorizontalExtent();
    int k = localGrid.getVerticalBeginValue();
    k = this.verticalValue;
    localGrid.setVerticalBeinValue(k);
    int l = localGrid.getHorizontalBeginValue();
    l = this.horizontalValue;
    localGrid.setHorizontalBeginValue(l);
    this.gridSize = localGrid.getSize();
    this.verticalEndValue = (this.verticalValue + i + 1);
    this.horizontalEndValue = (this.horizontalValue + j + 1);
    double d1 = this.gridSize.getWidth();
    double d2 = this.gridSize.getHeight();
    if (!(localReportPane.isRowEndless()))
    {
      i1 = localTemplateReport.getRowCount();
      this.verticalEndValue = Math.min(this.verticalEndValue, i1);
      d2 = this.rowHeightList.getRangeValue(this.verticalValue, Math.max(0, i1));
    }
    if (!(localReportPane.isColumnEndless()))
    {
      i1 = localTemplateReport.getColumnCount();
      this.horizontalEndValue = Math.min(this.horizontalEndValue, i1);
      d1 = this.columnWidthList.getRangeValue(this.horizontalValue, Math.max(0, i1));
    }
    this.gridSize = localGrid.getSize();
    paintBackground(localGraphics2D, localGrid, localTemplateReport, localReportSettings);
    paintGridLine(localGraphics2D, localGrid, d1, d2);
    this.paintCellElementList.clear();
    this.paintCellElementRectangleList.clear();
    paintCellElements(localGraphics2D, localGrid, localTemplateReport);
    paintPaginateLines(localGraphics2D, localGrid);
    paintGridSelection(localGraphics2D, localGrid, localTemplateReport);
    paintFloatElements(localGraphics2D, localGrid, localTemplateReport);
    paintDragCellBorder(localGraphics2D, localGrid);
    localGrid.ajustEditorComponentBounds(localReportPane);
  }

  public void caculateScrollVisibleBounds(Rectangle2D.Double paramDouble, CellElement paramCellElement)
  {
    caculateScrollVisibleBounds(paramDouble, paramCellElement.getColumn(), paramCellElement.getRow(), paramCellElement.getColumnSpan(), paramCellElement.getRowSpan());
  }

  public void caculateScrollVisibleBounds(Rectangle2D.Double paramDouble, Rectangle paramRectangle)
  {
    caculateScrollVisibleBounds(paramDouble, paramRectangle.x, paramRectangle.y, paramRectangle.width, paramRectangle.height);
  }

  public void caculateScrollVisibleBounds(Rectangle2D.Double paramDouble, int paramInt1, int paramInt2, int paramInt3, int paramInt4)
  {
    if ((paramInt1 > this.horizontalEndValue) || (paramInt2 > this.verticalEndValue) || (paramInt1 + paramInt3 <= this.horizontalValue) || (paramInt2 + paramInt4 <= this.verticalValue))
    {
      paramDouble.x = INVALID_INTEGER;
    }
    else
    {
      paramDouble.x = this.columnWidthList.getRangeValue(this.horizontalValue, paramInt1);
      paramDouble.y = this.rowHeightList.getRangeValue(this.verticalValue, paramInt2);
      paramDouble.width = this.columnWidthList.getRangeValue(paramInt1, paramInt1 + paramInt3);
      paramDouble.height = this.rowHeightList.getRangeValue(paramInt2, paramInt2 + paramInt4);
    }
  }

  public static boolean validate(Rectangle2D paramRectangle2D)
  {
    return ((paramRectangle2D != null) && (paramRectangle2D.getX() != INVALID_INTEGER));
  }

  public void calculateForcedPagingOfCellElement(ReportPane paramReportPane, CellElement paramCellElement, double paramDouble1, double paramDouble2)
  {
    double d1;
    double d2;
    if (paramCellElement == null)
      return;
    CellPageAttr localCellPageAttr = paramCellElement.getCellPageAttr();
    if (localCellPageAttr == null)
      return;
    TemplateReport localTemplateReport = paramReportPane.getEditingReport();
    DynamicValueList localDynamicValueList1 = ReportHelper.getColumnWidthList(localTemplateReport);
    DynamicValueList localDynamicValueList2 = ReportHelper.getRowHeightList(localTemplateReport);
    int i = paramReportPane.getSize().width;
    int j = paramReportPane.getSize().height;
    if (localCellPageAttr.isPageAfterColumn())
    {
      d1 = localDynamicValueList1.getRangeValueFromZero(paramCellElement.getColumn() + paramCellElement.getColumnSpan()) - paramDouble1;
      this.paginateLineList.add(new Line2D.Double(d1, 0.0D, d1, j));
    }
    if (localCellPageAttr.isPageBeforeColumn())
    {
      d1 = localDynamicValueList1.getRangeValueFromZero(paramCellElement.getColumn()) - paramDouble1;
      this.paginateLineList.add(new Line2D.Double(d1, 0.0D, d1, j));
    }
    if (localCellPageAttr.isPageAfterRow())
    {
      d2 = localDynamicValueList2.getRangeValueFromZero(paramCellElement.getRow() + paramCellElement.getRowSpan()) - paramDouble2;
      this.paginateLineList.add(new Line2D.Double(0.0D, d2, i, d2));
    }
    if (localCellPageAttr.isPageBeforeRow())
    {
      d2 = localDynamicValueList2.getRangeValueFromZero(paramCellElement.getRow()) - paramDouble2;
      this.paginateLineList.add(new Line2D.Double(0.0D, d2, i, d2));
    }
  }
}